<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" session="true"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="beans.CommanderBean"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Login </title>
</head>
<body>
<jsp:useBean id="activeUser" class="beans.UserBean" scope="session" />
<jsp:setProperty name="activeUser" property="*"/>
<center>
<%
	String []part={"LOGIN:USER=",",PASSWD="};
	if(activeUser!=null){
		String loginCmd = part[0]+activeUser.getUsername()+part[1]+activeUser.getPassword();	
		CommanderBean commander = new CommanderBean();
		String reply = commander.sendCommand(loginCmd);
		int pos = reply.indexOf('=')+1;

		String statePrompt ;
		if(reply.substring(pos,pos+1).startsWith("0")){
			session.setAttribute("loginCmd",loginCmd);
			statePrompt = "Login Successfully!";
			commander.close();
			request.setAttribute("statePrompt",statePrompt);
%>
			<jsp:forward page="listVMs.jsp"/>
<%		} else {
			commander.close();
%>
			<jsp:forward page="index.jsp">
				<jsp:param name="state" value="1"/>
			</jsp:forward>
<%		}  	
	}else{out.println("Error!");}
%>
	
</center>

</body>
</html>